package interview.careercup;


public class Chapter1 {
	/*
	protected long Fib(int n){
		long fibNum = 0;
	  if(n<0){
		  //Show error msg
		  return -1;
	  }else if(n==0){
		  return 0;
	  }else if(n==1){
		  return 1;
	  }else{
	  
		  long i0=0, i1=1;
		while(n>=2){
			fibNum = i0+i1;
			i0=i1;
			i1=fibNum;
			//
			n--;
		}
	  
	  }
	
	}
	*/
	protected long FibRecursive(int n){
		if(n<=0){
			//Log and show error msg
			
			return -1;
		}
		else if(n==1){
			return 1;
		}else if(n==0){
			return 0;
		}else{
			return FibRecursive(n-1)+FibRecursive(n-2);
		}
		}
	
	/**
	 * Return 2's between 0 and n
	 * @param n scope
	 * @return count of 2's
	 */
	/*
	protected LinedList<int> count2s(int n){
		
		if(n<0){
			// Log and show error msg
			return null;
		}else if(n<=1){
			return null;
		}else{
			LinedList<int> all2s = new LinedList<int>();
			int counter = 0;
			for(int i=0;i<=n;i++){
				if(check2s(i)){
					all2s.add(i);
				}
			}
			return all2s;
		}
		
		}
	private boolean check2s(int m){
		int k=2;
		while(k<=m){
			int mAndk = m & k;
			if(mAndk==k){
				return true;
			}else{
				k*=10;
			}
		
		}
		return false;
	}
*/
	/**
	 * check the intersection of two lines(segment)
	 * @param x1s
	 * @param y1s
	 * @param x1e
	 * @param y1e
	 * @param x2s
	 * @param y2s
	 * @param x2e
	 * @param y2e
	 * @return
	 */
	/*
	protected boolean checkIntersect(int x1s, int y1s, int x1e, int y1e, int x2s, int y2s, int x2e, int y2e){
		int x1min, x1max, x2min, x2max;
		int y1min, y1max, y2min, y2max;
		
		if(x1s>x1e){
			x1max=x1s;
			x1min = x1e;
		}else{
			x1max=x1e;
			x1min = x1s;
		}
		if(y1s>y1e){
			y1max=y1s;
			y1min = y1e;
		}else{
			y1max=y1e;
			y1min = y1s;
		}
		if(x2s>x2e){
			x2max=x2s;
			x2min = x2e;
		}else{
			x2max=x2e;
			x2min = x2s;
		}
		if(y2s>y2e){
			y2max=y2s;
			y1min = y1e;
		}else{
			y2max=y2e;
			y2min = y2s;
		}
		
		//if(x1min<x2max && x1y)
	}
	*/
	/**
	 * 
	 * @param n
	 * @return
	 */
	protected int CountNFactorial(int n){
		
		if(n<0){
			//Log and show error msg
			return -1;
		}else if(n<5){
			return 0;
		}else{
			int counter = 0;
			long facN =n;
			while(n>1){
				facN*=(n-1);
				//
				n--;
			}
			long fac9 = 9;
			while(fac9<facN){
				long xorResult = facN ^ fac9;
				if(xorResult==fac9){
					counter++;
				}
				//
				fac9*=10;
		}
			return counter;
	}
	}


}

